include_directories(../libzip ../SimpleIni)

configure_file(libOSGi++.res.rc.in libOSGi++.res.rc)

add_library(OSGi++ SHARED
    Exception.cc
    Utils.cc
    Platform.cc
    Properties.cc
    ConfigFile.cc
    Activator.cc
    Version.cc
    Service.cc
    ServiceRegistry.cc
    LifeCycle.cc
    Bundle.cc
    BundleFactory.cc
    Context.cc
    BundleInstallerService.cc
    BundleMgr.cc
    ExtensionPoint.cc
    ExtensionPointService.cc
    ApplicationService.cc
    $<TARGET_OBJECTS:zip>
    $<TARGET_OBJECTS:TinyXml>
    $<TARGET_OBJECTS:SimpleIni>
    ${CMAKE_CURRENT_BINARY_DIR}/libOSGi++.res.rc
)

if(UNIX)
    target_link_libraries(OSGi++ -ldl)
endif()

if(MINGW)
    # Because implib seems not to work as expected...
    add_custom_command(TARGET OSGi++ POST_BUILD COMMAND cp -f "$<TARGET_FILE:OSGi++>" "$<TARGET_LINKER_FILE:OSGi++>")
endif()

set_target_properties(OSGi++ PROPERTIES
    VERSION                  ${OSGi_VERSION}
    SOVERSION                ${OSGi_VERSION_MAJOR}
)

if(WIN32)
    set_target_properties(OSGi++ PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${OSGi_BINARY_DIR}/bin)
else()
    set_target_properties(OSGi++ PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${OSGi_BINARY_DIR}/lib)
endif()

install(TARGETS OSGi++
    EXPORT OSGiTargets
    DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib
)
